package br.com.vemtransporte;

import java.util.ArrayList;

import br.com.vemtransporte.basicas.Linha;
import br.com.vemtransporte.fachada.Fachada;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ExpandableListView;
import android.widget.ListView;
import android.widget.Toast;

public class TelaHorarios extends Activity {
	private ExpandableListView expandableListViewHorarios;
	private ArrayList<Linha> linhas = null;
	private ExpandableListHorarios adapter;

	private Handler handler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			adapter.notifyDataSetChanged();
			super.handleMessage(msg);
		}
	};

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.horarios);
		
		Button btOKHorarios = (Button) findViewById(R.id.buttonOKHorarios);
		btOKHorarios.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				finish();				
			}
		});

		expandableListViewHorarios = (ExpandableListView) findViewById(R.id.expandableListViewHorarios);

		try {
			this.linhas = Fachada.getInstance().ProcurarLinhaHorarioTodos();

			if (this.linhas != null) {

				adapter = new ExpandableListHorarios(
						(ArrayList<Linha>) this.linhas, TelaHorarios.this);

				expandableListViewHorarios.setAdapter(adapter);

				handler.sendEmptyMessage(1);
			} else {
				Toast.makeText(getBaseContext(), "Nenhuma linha encontrada!",
						Toast.LENGTH_LONG).show();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
